'use strict';
exports = module.exports = function ($scope, $rootScope, $timeout, $alert, $state, $uibModal, $ajax, $API, throttleSubmit, $rule) {
    $scope.Rule = $rule;
    $scope.frm = {
        f23: '', //文件上传
        f24: '', //文件上传
    };
    $scope.frm2 = {
        f23: null, //文件对象
        f23upload: function(){
            //根据自己需要的类型进行判断
            var file = $scope.frm2.f23;
            if( file.type != 'image/png' ){
                $alert.error('请上传png格式图片')
                return;
            }
            _upload();
            function _upload(){
                var data = new FormData(); //存储文件格式流数据
                data.append('addFile', file);
                var option = {
                    real: true,
                    url: '/ng1x/fileUpload',
                    method: 'POST',
                    data: data, //仅仅存放的是文件流数据
                    headers: { 'Content-Type': undefined }, //angularjs设置文件上传的content-type修改方式
                    transformRequest: angular.identity
                };
                $ajax.sent(option).then((res) => { /*图片上传完成返回临时路径该给谁给谁*/
                    console.log(res);
                    $timeout(function(){
                        $scope.frm.f23 = res.data.path;
                    },0)
                }).catch((res) => {
                    console.error(res);
                });
            }
        },
        f24: null, //文件对象
        f24upload: function(){
            //根据自己需要的类型进行判断
            var file = $scope.frm2.f24;
            if( file.type != 'image/png' ){
                $alert.error('请上传png格式图片')
                return;
            }
            _upload();
            function _upload(){
                var data = new FormData(); //存储文件格式流数据
                data.append('addFile', file);
                var option = {
                    real: true,
                    url: '/ng1x/fileUpload',
                    method: 'POST',
                    data: data, //仅仅存放的是文件流数据
                    headers: { 'Content-Type': undefined }, //angularjs设置文件上传的content-type修改方式
                    transformRequest: angular.identity
                };
                $ajax.sent(option).then((res) => { /*图片上传完成返回临时路径该给谁给谁*/
                    console.log(res);
                    $timeout(function(){
                        $scope.frm.f24 = res.data.path;
                    },0)
                }).catch((res) => {
                    console.error(res);
                });
            }
        }
    };
    $scope.submitFun = throttleSubmit(function(){
        $scope.From.submitted = true;
        if( $scope.From.$invalid ) {
            $alert.error('请检查提交的信息')
            return false;
        }
        var param = {};
        return param
    },function(enable, param){
        console.log('提交代码', param)
        $timeout(function(){
            enable()
        },3e3)
    });
    $scope.cancelFun = function(){
        $alert.confirm("是否取消编辑？", function(close){
            // $go('app.make.maketable1');
            close();
        })
    };
}